_require "basis.smi"
_require "./base.sig"
_require "utils.sig"
_require "sigs.sml"

structure Header =
struct
  type pos = int
  val lineno : pos ref
  val text : string list ref
  type inputSource = {name : string,
                      errStream : TextIO.outstream,
                      inStream : TextIO.instream,
                      errorOccurred : bool ref}
  val newSource : string * TextIO.instream * TextIO.outstream -> inputSource
  val error : inputSource -> pos -> string -> unit
  val warn : inputSource -> pos -> string -> unit
  val errorOccurred : inputSource -> unit -> bool
  datatype symbol = SYMBOL of string * pos
  val symbolName : symbol -> string
  val symbolPos : symbol -> pos
  val symbolMake : string * int -> symbol
  type ty = string
  val tyName : ty -> string
  val tyMake : string -> ty
  datatype prec = LEFT | RIGHT | NONASSOC
  datatype control = NODEFAULT | VERBOSE | PARSER_NAME of symbol |
                     FUNCTOR of string  | START_SYM of symbol |
                     NSHIFT of symbol list | POS of string | PURE |
                     PARSE_ARG of string * string
  datatype rule = RULE of {lhs : symbol, rhs : symbol list,
                           code : string, prec : symbol option}
  datatype declData = DECL of
                      {eop : symbol list,
                       keyword : symbol list,
                       nonterm : (symbol * ty option) list option,
                       prec : (prec * (symbol list)) list,
                       change: (symbol list * symbol list) list,
                       term : (symbol * ty option) list option,
                       control : control list,
                       value : (symbol * string) list}
  val join_decls : declData * declData * inputSource * pos -> declData
  type parseResult = string * declData * rule list
  val getResult : parseResult -> string * declData * rule list
end
